package cn.edu.gcu.ssl.goods.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRange;
import org.springframework.stereotype.Controller;
import org.springframework.util.IdGenerator;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.edu.gcu.ssl.goods.entity.Goods;
import cn.edu.gcu.ssl.goods.service.GoodsService;
import cn.edu.gcu.ssl.system.util.U2id;
@Controller
@RequestMapping(value="/goods")
public class GoodsController {
	
	@Autowired
	private GoodsService goodService;
		
	@ResponseBody	
	@RequestMapping(value="/findList")
	public Map<String, Object>findList(@RequestParam(required=false,value="type")String type)
	{
		Map<String, Object>map=new HashMap<String,Object>();
		  
		map.put("data",goodService.findList(type));
		return map;
		
	}
	
	@ResponseBody	
	@RequestMapping(value="/save")
	public Map<String, Object>save(Goods goods,HttpServletRequest request)
	{
		Map<String, Object>map=new HashMap<String,Object>();
		if(goods==null)
		{
			map.put("result","error");
		}
		goods.setId(U2id.getUUID()); 
		goods.setDate(new Date());
	
		if(goodService.insert(goods))
		{
			map.put("result", "success");
		
		}
		else {
			map.put("result", "error");
		}
		
		
		return map;
		
	}
	
	@ResponseBody	
	@RequestMapping(value="/delete")
	public Map<String, Object>delete(String id,HttpServletRequest request)
	{
		Map<String, Object>map=new HashMap<String,Object>();		
	
		if(goodService.deleteByPrimaryKey(id))
		{
			map.put("result", "success");
		
		}
		else {
			map.put("result", "error");
		}
				
		return map;
		
	}
	
	
	
	
	
}
